<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class AlipayController extends Controller
{
    /*
     * 支付处理结果
     * */
   public function pay()
   {
       $gateway = Omnipay::gateway();
       /*
        * 模拟订单
        * */
       $options = [
           'out_trade_no' => date('YmdHis') . mt_rand(1000,9999), //订单号
           'subject' => 'Alipay Test',//订单名称
           'total_fee' => '0.01', //价格
       ];

        $response = $gateway->purchase($options)->send();
        $response->redirect();


   }

   /*
    * 支付返回结果
    * */

   public function result(Request $request)
   {
        $gateway = Omnipay::gateway();
        $options = [
            'request_params' => $request->all(),
        ];
       $response = $gateway->completePurchase($options)->send();

       if($response->isSuccessful() && $response->isTradestatusOk()){
           //支付成功后的操作

           exit('支付成功');

       }else{
           //支付失败的通知
           exit('支付失败');
       }
   }
}